package com.shenfa.action;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.shenfa.bean.SystemTranCode;
import com.shenfa.service.SystemTranCodeService;

import com.shenfa.util.ResultObject;

/**
 * 系统管理-交易代码 Action
 * 
 * @author 张瑶
 * @date 2011-08-24
 */
public class SystemTranCodeAction extends BaseAction {

	private static final long serialVersionUID = -8191987188017097147L;
	
	@Autowired
	private SystemTranCodeService systemTranCodeService;
	
	private static Logger log=Logger.getLogger(SystemTranCodeAction.class);
	private SystemTranCode systemTranCode;
	private int start;
	private int limit;
	
	/**
	 * 验证交易代码主键唯一性
	 */
	public String validKey() {
		log.debug("systemTranCode="+systemTranCode);
		int flag = systemTranCodeService.validateSystemTranCode(systemTranCode);
		result = ResultObject.build(String.valueOf(flag), null);
		return SUCCESS;
	}
	
	/**
	 * 模糊查询交易代码信息
	 */
	@SuppressWarnings("unchecked")
	public String selectSystemTranCode() {
		log.debug("systemTranCode="+systemTranCode+",start="+start+",limit="+limit);
		List<SystemTranCode> list = systemTranCodeService.selectSystemTranCode(systemTranCode, start, limit);
		result = ResultObject.build("0", list);
		result.put("total", systemTranCodeService.getCount(systemTranCode));
		return SUCCESS;
	}

	/**
	 * 增加交易代码信息
	 */
	public String insertSystemTranCode() {
		log.debug(systemTranCode.toString());
		int type = systemTranCodeService.insertSystemTranCode(systemTranCode);
		if(type == 1){
			result = ResultObject.build(String.valueOf(type), "添加成功！");
		} else {
			result = ResultObject.build(String.valueOf(type), "操作失败！");
		}
		return SUCCESS;
	}

	/**
	 * 更新交易代码信息
	 */
	public String updateSystemTranCode() {
		log.debug(systemTranCode.toString());
		int type = systemTranCodeService.updateSystemTranCode(systemTranCode);
		if(type == 1){
			result = ResultObject.build(String.valueOf(type), "更新成功！");
		} else {
			result = ResultObject.build(String.valueOf(type), "操作失败！");
		}
		return SUCCESS;
	}

	/**
	 * 刪除交易代码信息
	 * 
	 * @return
	 */
	public String deleteSystemTranCode() {
		log.debug(systemTranCode.toString());
		int type = systemTranCodeService.deleteSystemTranCode(systemTranCode);
		if(type == 1){
			result = ResultObject.build(String.valueOf(type), "删除成功！");
		} else {
			result = ResultObject.build(String.valueOf(type), "操作失败！");
		}
		return SUCCESS;
	}

	public SystemTranCode getSystemTranCode() {
		return systemTranCode;
	}

	public void setSystemTranCode(SystemTranCode systemTranCode) {
		this.systemTranCode = systemTranCode;
	}
	
	public void setStart(int start) {
		this.start = start;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

}
